<% if @role
  breadcrumbs(
    items: [
      {
        caption: _("Roles"),
        url: (roles_path if authorized_for(hash_for_roles_path))
      },
      {
        caption: _("%s filters") % @role.to_s
      }
    ]
  )
else
  title _("Filters")
end %>

<% title_actions new_link_unless_locked(_("Create Filter"), { :controller => :filters, :role_id => @role }, @role),
                 documentation_button('4.1.2RolesandPermissions') %>

<table class="<%= table_css_classes 'table-fixed' %>" <%= "data-table='inline'".html_safe if params[:paginate] == 'client' %> >
  <thead>
    <tr>
      <% unless params[:role_id] %>
        <th><%= sort :role, :as => _("Role"), :permitted => [:role_id] %></th>
      <% end %>
      <th><%= sort :resource, :as => s_("Filter|Resource"), :permitted => [:role_id] %></th>
      <th><%= s_("Filter|Permissions") %></th>
      <th><%= sort :search, :as => s_("Filter|Unlimited"), :permitted => [:role_id] %></th>
      <th><%= sort :search, :as => s_("Filter|Override"), :permitted => [:role_id] %></th>
      <th><%= sort :search, :as => s_("Filter|Search"), :permitted => [:role_id] %></th>
      <% if @role && !@role.locked? %>
        <th><%= _('Actions') %></th>
      <% end %>
    </tr>
  </thead>
  <tbody>
    <% @filters.each do |filter| %>
      <tr>
        <% unless params[:role_id] %>
          <td>
            <%= content_tag('span', link_to_if_authorized(filter.role.name, hash_for_roles_path(:search => "name = #{filter.role.name}").
                  merge(:auth_object => filter.role, :authorizer => @roles_authorizer))) %>
          </td>
        <% end %>
        <td>
          <%= _( filter.resource_type_label ) %>
        </td>
        <td><%= filter.permissions.map(&:name).join(', ') %></td>
        <td><%= checked_icon filter.unlimited? %></td>
        <td><%= checked_icon filter.override? %></td>
        <td>
          <%= content_tag('span', link_to_unless_locked(filter.search || _('N/A'), @role,
                                                      hash_for_edit_filter_path(:id => filter, :role_id => @role).
                                                              merge(:auth_object => filter, :authorizer => authorizer))) %>
        </td>
        <% if @role && !@role.locked? %>
          <td>
            <% buttons = [] %>
            <% buttons.push display_link_if_authorized(_("Edit"), hash_for_edit_filter_path(:id => filter, :role_id => @role).
                              merge(:auth_object => filter, :authorizer => authorizer)) %>
            <% buttons.push display_link_if_authorized(_("Disable overriding"), hash_for_disable_overriding_filter_path(:id => filter, :role_id => @role).
                              merge(:auth_object => filter, :authorizer => authorizer), :method => :patch) if filter.override? %>
            <% buttons.push display_delete_if_authorized(hash_for_filter_path(:id => filter, :role_id => @role).
                                                           merge(:auth_object => filter, :authorizer => authorizer),
                                                           :data => { :confirm => (_("Delete filter?")) } ) %>

            <%= action_buttons(buttons) %>
          </td>
        <% end %>
      </tr>
    <% end %>
  </tbody>
</table>
<%= will_paginate_with_info(@filters) unless params[:paginate] == 'client' %>
